{extend name="base" /}
{block name="body"}

<div class="layui-card">
    <div class="layui-card-body">
        <div style="margin-top: 5px">
            <p style="float: left;margin-top: 7px">日期选择：</p>
            <input class="layui-input" id="start_time" name="start_time" style="width: 10%;float: left;margin-left: 20px;"  >

            <p style="float: left;margin-top: 7px;margin-left: 20px;" >---</p>
            <input class="layui-input" id="end_time" name="end_time" style="width: 10%;float: left;margin-left: 20px;"  >
            <input id="gid" name="gid" hidden="hidden" value="{$gid}" >
            <p style="float: left;margin-top: 7px;margin-left: 20px">业务员：</p>
            <input name="code" style="float: left;width: 200px;height: 35px;margin-left: 20px" id="code" placeholder="请输入业务员编码">
            <input name="ccode" style="float: left;width: 200px;height: 35px;margin-left: 20px" id="ccode" placeholder="请输入渠道编码">

            <p style="float: left;margin-top: 7px;margin-left: 20px">选择机构：</p>
            <select name="agency" lay-verify="required" style="width: 100px;height: 35px;margin-left: 20px" id="agency">
                <option value="">全部</option>
                {volist name='agency' id='vo'}
                <option value="{$vo.id}">{$vo.name}</option>
                {/volist}
            </select>
            <button class="layui-btn search" data-type = "reload"  style="margin-left: 20px">搜索</button>

            <a id="delAll" class="layui-btn" data-width="830px" data-height="800px" style="margin-left: 20px"><i class="fa fa-minus-circle"></i> 删除</a>
        </div>
    </div>

    <table id="tableList" lay-filter="tableList"></table>
    <!-- 表格操作列 -->
    <script type="text/html" id="tableTBTrack">
        <a href="{:url('admin/groups/groups_employ_del')}?id={{d.id}}" class="layui-btn  layui-btn-sm layui-btn-danger ajax-delete">删除</a>
    </script>

    <!-- 权限列 -->
    <script type="text/html" id="sort_order">
        <input type="text" value="get_ad({{d.id}},'desc')" autocomplete="off" class="layui-input" disabled>
    </script>
</div>

{/block}
{block name="js"}

<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start_time' //指定元素
        });
        laydate.render({
            elem: '#end_time' //指定元素
        });
    });

    layui.use(['layer', 'form', 'table', 'util', 'dropdown'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var dropdown = layui.dropdown;

        // 渲染回访表格
        var insTb = table.render({
            elem: '#tableList',
            url: "{:url('admin/groups/employee_json')}?gid="+$('#gid').val(),
            page: true,
            limit:10,
            limits:[15,30,45,60,75,90],
            cellMinWidth: 100,
            size:'lg',even:true,
            cols: [[
                {type: 'checkbox', fixed: 'left'},
                {type:'numbers',title:'#'},
                {field: 'ccode', title: '渠道码'},
                {field:'cname', title: '渠道名称'},
                {field:'code', title: '员工码'},
                {field:'cname', title: '所在分组'},
                {field:'name', title: '微信昵称'},
                {field:'phone', title: '手机号'},
                {field:'create_time', title: '初次登陆日期'},
                {align: 'center', toolbar: '#tableTBTrack', title: '操作', width: 150}
            ]],
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },id: 'testReload'
        });

        var $ = layui.$, active = {
            reload: function(){
                var agency = $('#agency');

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        aid: agency.val(),
                        ccode: $('#ccode').val(),
                        code: $('#code').val(),
                        start_time: $('#start_time').val(),
                        end_time: $('#end_time').val()
                    }
                }, 'data');
            }
        };

        $('.search').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

    $('#delAll').click(function(){
        var data = table.cache.testReload;
        var ids = [];

        for(let i = 0;i<data.length;i++){
            if(data[i]['LAY_CHECKED'] == true){
                ids.push(data[i]['id']);
            }
        }

        if(ids.length == 0){
            layer.open({
                content: '请先勾选' //这里content是一个普通的String
            });
            return;
        }

        layer.confirm('确定要删除吗', {icon: 3, title:'提示'}, function(index){
            $.ajax({
                url:'groups_employ_del',
                data:{'id':ids},
                method:'post',
                success:function(res){
                    layer.open({
                        content: res.msg //这里content是一个普通的String
                    });
                    window.location.reload();
                }
            });
        });
    })



</script>
{/block}